package com.mavenq.fly.websocket.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class WSMessage {
    private String type;       // 必填：auth | message | ping | pong | broadcast | uni
    private String token;      // auth 时必填
    private String userId;     // uni 时必填（单播目标）
    private String content;    // 消息内容

    // 便捷构造
    public static WSMessage auth(String token, String userId) {
        return new WSMessage("auth", token, userId, null);
    }

    public static WSMessage broadcast(String content) {
        return new WSMessage("broadcast", null, null, content);
    }

    public static WSMessage uni(String toUserId, String content) {
        return new WSMessage("uni", null, toUserId, content);
    }

    public static WSMessage ping() {
        return new WSMessage("ping", null, null, null);
    }

    public static WSMessage pong() {
        return new WSMessage("pong", null, null, null);
    }
}